/**
 * 
 */
package com.wistech.search.solr4;

import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * @author Liuye
 * 
 */
public final class SolrHelper {
	private static final Logger log = LoggerFactory.getLogger(SolrHelper.class);
	private SolrServer solrServer;

	public SolrHelper(SolrServer solrServer) {
		this.solrServer = solrServer;
	}

	public Long count() {
		try {
			return solrServer.query(new SolrQuery("*:*")).getResults()
					.getNumFound();
		} catch (Exception e) {
			String msg = "delete all searchable object in search server error.";
			log.error(msg, e);
			throw new SearchException(msg, e);
		}
	}

	public void clean() {
		try {
			solrServer.deleteByQuery("*:*");
		} catch (Exception e) {
			String msg = "delete all searchable object in search server error.";
			log.error(msg, e);
			throw new SearchException(msg, e);
		}
	}
}
